import Dexie, { type EntityTable } from 'dexie';

interface Book {
  id: string;
  name: string;
  type: string;
  file: File;
  cover: string | undefined | null;
  createTime: number;
  lastTime?: number;
  currentIndex: number;
  password: string | null
}

const db = new Dexie('BooksDatabase') as Dexie & {
  books: EntityTable<Book, 'id'>;
};

// Schema declaration:
db.version(1).stores({
  books: '++id, name, type, file, cover, createTime, lastTime, currentIndex, password' // primary key "id" (for the runtime!)
});

export type { Book };
export { db };
